package com.qf.servlet;

import com.qf.entity.Registration;
import com.qf.entity.RegistrationVo;
import com.qf.service.RegistrationService;
import com.qf.service.impl.RegistrationServiceImpl;
import com.qf.utils.PageUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "registrationServlet",urlPatterns = "/registrationServlet")
public class RegistrationServlet extends BseServlet{
    private RegistrationService registrationService;
    private RegistrationVo registrationVo;

    @Override
    public void init(ServletConfig config) throws ServletException {
        registrationService = new RegistrationServiceImpl();
        //registrationVo = new RegistrationVo();
    }

    public void selectRegistration(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取当前页于页量
        String currentPageNo = req.getParameter("currentPageNo");
        String pageSize = req.getParameter("pageSize");

        //获取条件查询的参数
        String rid = req.getParameter("rid");
        String dname = req.getParameter("dname");
        String startTime = req.getParameter("startTime");
        String endTime = req.getParameter("endTime");
        //实例化并且赋值
        RegistrationVo registrationVo = new RegistrationVo(rid,dname,startTime,endTime);


        //调用Service层
        PageUtils<Registration> pageUtils = registrationService.selectByPage(registrationVo, currentPageNo, pageSize);
        //存进作用域
        req.setAttribute("pageUtils",pageUtils);
        req.setAttribute("registrationVo",registrationVo);

        //实现页面转发
        req.getRequestDispatcher("registration/index.jsp").forward(req,resp);
    }
}
